package com.Servlet;

import com.Bean.Ticket;
import com.Util.DB;
import com.Util.TkDao;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/createtk")
public class createtk extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String username= req.getParameter("username");
        String subject=req.getParameter("subject");
        Ticket tk = new Ticket();
        tk.setUsername(username);
        tk.setSubject(subject);
        tk.setTypes("support");
        tk.setStatus("open");
        if (DB.isDebug()) {
            JSONObject jb = JSONObject.fromObject(tk);
            String tojson = jb.toString();
            System.out.println(tojson);
        }
        TkDao.insertTk(tk);
        resp.sendRedirect("./serve/tickets.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
